/**
 * \file Symbol.cpp
 *
 * Asteriskos Compiler 1
 * Written 2010-2011, by Anthony Berlin and Alexander Carlqvist
 *
 * This file is part of ICC.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "Symbol.h"
#include <boost/lexical_cast.hpp>

///
/// Constructor for 'Symbol'.
///
Symbol::Symbol() : m_token(NULL_TOKEN), m_parent(NULL), m_ownScope(NULL), m_datatype(NULL),
    m_tree(NULL_TREE), m_definition(NULL_TREE), m_isParamDecl(false), m_modConst(false),
    m_modExtern(false), m_modStatic(false), m_isEvaluable(false), m_isDefined(false)
{
}

///
/// Returns a human readable string representation of this symbol.
///
string Symbol::to_string() const
{
    string result;

    result = (string)"<symbol : " + boost::lexical_cast<string>(this) + ">";

    if (m_token != NULL_TOKEN)
        result += (string)", <token : " + m_token->m_lexeme + ">";

    if (m_ownScope != NULL)
        result += ", <has own scope>";

    if (m_datatype != NULL)
        result += (string)", <datatype : " + m_datatype->to_string() + ">";

    if (m_isParamDecl)
        result += ", <is param-decl>";

    if (m_modConst || m_modExtern || m_modStatic)
    {
        result += ", <modifiers : ";
        if (m_modConst)
            result += "const";
        if (m_modConst && m_modExtern)
            result += ", extern";
        else
            result += "extern";
        if ((m_modConst || m_modExtern) && m_modStatic)
            result += ", static";
        else
            result += "static";
    }

    return result;
}
